package com.apartment.poi;

import com.apartment.poi.domin.ContractTemplate;
import com.deepoove.poi.XWPFTemplate;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;

/**
 * @program: HousingRental_tenant_Server_JAVA
 * @description: 合同模板
 * @author: @Dog_E
 * @create: 2020-09-09 16:41
 **/
public class TenantContractTools {


    /**
     * @param contractTemplate: 合同模板实例
     * @Description:生成合同
     * @return: void
     * @Author: @Dog_E
     * @Date: 2020/9/9 0009 16:47
     **/
    public static void generateContract(ContractTemplate contractTemplate) {
        HashMap map = new HashMap<String, Object>();
        map.put("合同编号",contractTemplate.getContractNo());
        map.put("甲方名称",contractTemplate.getNameOfPartyA());
        map.put("乙方名称",contractTemplate.getNameOfPartyB());
        map.put("租客姓名",contractTemplate.getTenantName());
        map.put("租客证件类型",contractTemplate.getTenantIDType());
        map.put("租客证件号",contractTemplate.getTenantIDNumber());
        map.put("户籍地址",contractTemplate.getResidenceAddress());
        map.put("租客电话",contractTemplate.getTenantPhone());
        map.put("城市",contractTemplate.getCity());
        map.put("物理地址",contractTemplate.getPhysicalAddress());
        map.put("楼层",null);
        map.put("总层高",null);
        map.put("房间面积",null);
        map.put("合同起始日期",contractTemplate.getContractStartDate());
        map.put("合同结束日期",contractTemplate.getContractEndDate());
        map.put("合同总周期",null);
        map.put("交房日期",contractTemplate.getHandoverDate());
        map.put("押金金额",null);

        XWPFTemplate template = XWPFTemplate.compile("C:\\Users\\Administrator\\Desktop\\代码生成\\合同模板.docx").render(map);
        try {
            FileOutputStream out = new FileOutputStream("output.docx");
            template.write(out);
            out.flush();
            out.close();
            template.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
